import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/gaps.dart';
import 'package:ls_work/viewmodel/medecine/receive_medicine/add_receive_medicine_viewm_model.dart';
import 'package:ls_work/widgets/common_widget.dart';

class AddReceiveMedicinePage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _AddReceiveMedicineState();
}

class _AddReceiveMedicineState
    extends BaseMvvmState<AddReceiveMedicineViewModel, AddReceiveMedicinePage> {
  @override
  Widget? buildLoadingContentView() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            children: [
              TitleValueWidget(
                      title: '长者姓名',
                      value: viewModel.elderInfo?.customerName ?? "",
                      arrow: Icon(Icons.keyboard_arrow_right_outlined))
                  .onTap(() {
                viewModel.chooseElder();
              },
                      highlightColor: Colors.transparent,
                      splashColor: Colors.transparent),
              TitleValueWidget(
                  title: '床位号',
                  value: viewModel.elderInfo?.bedNo ?? "",
                  hint: '根据长者自动显示'),
              TitleValueWidget(
                  title: '性别',
                  value: viewModel.elderInfo?.sexName ?? "",
                  hint: '根据长者自动显示'),
              TitleValueWidget(
                      title: '药品名称',
                      value: viewModel.drugInfo?.commonName ?? "",
                      arrow: Icon(Icons.keyboard_arrow_right_outlined))
                  .onTap(() {
                viewModel.chooseMedicine();
              },
                      highlightColor: Colors.transparent,
                      splashColor: Colors.transparent),
              TitleValueWidget(
                  title: '药品规格',
                  value: "${viewModel.drugInfo?.specifications ?? ""}",
                  hint: '根据选择的药品自动显示'),
              TitleValueWidget(
                  title: '包装单位',
                  value: "${viewModel.drugInfo?.maxUnitName ?? ""}",
                  hint: '根据选择的药品自动显示'),
              TitleValueWidget(
                  title: '最小单位',
                  value: "${viewModel.drugInfo?.minUnitName ?? ""}",
                  hint: '根据选择的药品自动显示'),
              TitleContentWidget(
                  title: '入柜数量(包装)',
                  child: NoBorderInput(
                      hintText: '仅输入正整数',
                      onChanged: (str) {
                        viewModel.packageNum = str;
                        viewModel.calculateReceiveNum();
                      },
                      maxLines: 1,
                      keyboardType: CommonInputType.number)),
              TitleContentWidget(
                  title: '入柜数量(最小单位)',
                  child: NoBorderInput(
                      hintText: '仅输入正整数',
                      onChanged: (str) {
                        viewModel.unitNum = str;
                        viewModel.calculateReceiveNum();
                      },
                      maxLines: 1,
                      keyboardType: CommonInputType.number)),
              TitleValueWidget(
                  title: '合计入柜数量', value: viewModel.totalNum, hint: '自动计算')
            ].insertWidget(Gaps.dividerLine),
          ),
        ).setWeight(1),
        SizedBox(
          height: 12,
        ),
        TextButton(
          onPressed: () {
            viewModel.submitAdd();
          },
          child: CommonText('确认入柜', textColor: Colors.white),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colors.blue),
              shape: WidgetStateProperty.all(StadiumBorder()),
              minimumSize: WidgetStateProperty.all(
                  Size(MediaQuery.of(context).size.width - 32, 45))),
        ),
        SizedBox(
          height: 18,
        )
      ],
    );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text('新增收药入柜'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  AddReceiveMedicineViewModel createViewModel() {
    return AddReceiveMedicineViewModel(context);
  }

  @override
  void onRetryClick() {}
}
